package com.lottery.im.module.service.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.R;
import com.lottery.im.api.Api;
import com.lottery.im.api.result.entity.integral.Commodity;
import java.util.List;

/**
 * 作者：cyy
 * 时间：2018/9/17。
 */
public class CommodityAdapter extends BaseQuickAdapter<Commodity,BaseViewHolder>{

  private Context mContext;
  public CommodityAdapter(@Nullable List<Commodity> data,Context context) {
    super(R.layout.commodity_item, data);
    mContext=context;
  }

  @Override protected void convert(BaseViewHolder baseViewHolder, Commodity commodity) {
    int position = baseViewHolder.getAdapterPosition();
    ImageView image = baseViewHolder.getView(R.id.image);
    baseViewHolder.setText(R.id.tv_name,commodity.getC_name());
    String imgUrl;
    if(position==0){
      baseViewHolder.setText(R.id.tv_integral,"1积分兑换1元");
      imgUrl="android.resource://com.lottery.im/raw/img_jfdh";
    }else{
      baseViewHolder.setText(R.id.tv_integral,commodity.getPrice()+"积分");
      imgUrl=Api.BASEADDRESS+commodity.getImg();
    }
    Glide.with(mContext)
        .load(imgUrl)
        .apply(new RequestOptions().fitCenter()
            .placeholder(R.drawable.icon_conversation_de)
            .error(R.drawable.icon_conversation_de))
        .into(image);
  }
}
